package com.example.config;

import com.example.service.StorageService;
import com.example.service.impl.AliyunStorageService;
import com.example.service.impl.MinioStorageService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(StorageProperties.class)
public class StorageAutoConfiguration {

    @Bean
    @ConditionalOnProperty(name = "storage.type", havingValue = "minio")
    public StorageService minioStorageService(StorageProperties storageProperties) {
        return new MinioStorageService(storageProperties);
    }

    @Bean
    @ConditionalOnProperty(name = "storage.type", havingValue = "aliyun")
    public StorageService aliyunOssStorageService(StorageProperties storageProperties) {
        return new AliyunStorageService(storageProperties);
    }
}
